<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class TestData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test:data {--day=1}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'generate test data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $day = $this->option('day');
        $pdis = [ 
            't_hisdata_three'=>'1647895168', 
            't_hisdata_power'=>'2137862666', 
            't_hisdata_generalair'=>'2137862667', 
            't_hisdata_Switch'=>'2137862670', 
            't_hisdata_BatRout'=>'2137862669', 
            't_hisdata_ACSta'=>'2137862671', 
            't_hisdata_TempHumi'=>'2137862673', 
            't_hisdata_Generator'=>'2137862674', 
            't_hisdata_single'=>'2137862675',
        ];

        foreach($pdis as $t=>$pdi) {
            $this->call("generate:real2", [ 'pdi'=>$pdi ]);
            DB::statement("UPDATE {$t} SET hd_datetime=REPLACE(hd_datetime, date(date_sub(NOW(), interval {$day} day)), date(NOW())) WHERE pdi_index = {$pdi}");
        }

    }
}
